from django.db import models

# Create your models here.


# 用户表
class UserProfile(models.Model):
    password = models.CharField(max_length=64, verbose_name="密码")
    name = models.CharField(max_length=64, verbose_name="姓名")
    phone = models.CharField(verbose_name="手机号", max_length=32, null=True, blank=True)

    type_choices = (
        (1, "管理员"),
        (2, "普通用户"),
    )
    type = models.SmallIntegerField(verbose_name="用户类型", choices=type_choices, default=2)

    status_choices = (
        (1, "未激活"),
        (2, "在职"),
        (3, "离职"),
    )
    status = models.SmallIntegerField(choices=status_choices, verbose_name="状态", default=1)

    sex_choices = (
        (1, "女"),
        (2, "男"),
    )

    sex = models.SmallIntegerField(choices=sex_choices, verbose_name="性别", null=True, blank=True)

    department = models.ForeignKey('Department', verbose_name="部门", null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "用户信息表"


# 部门
class Department(models.Model):
    """部门"""
    name = models.CharField(verbose_name="部门名称", max_length=32, unique=True)
    superior = models.ForeignKey('self', verbose_name="上级部门", null=True, blank=True)  # 为空则表示为顶级部门

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "部门信息表"


# 客户表
class ClientInfo(models.Model):
    user = models.ForeignKey('UserProfile', verbose_name="所属用户")
    client_name = models.CharField(verbose_name="客户名称", max_length=64)
    contact_name = models.CharField(verbose_name="联系人姓名", max_length=64, null=True, blank=True)
    phone = models.CharField(verbose_name="手机号", max_length=32, null=True, blank=True)
    qq = models.CharField(verbose_name="QQ号", max_length=32, null=True, blank=True)
    create_date = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    update_date = models.DateTimeField(verbose_name="修改时间", auto_now=True)

    # status_choices = (
    #     (1, "初次沟通"),
    #     (2, "有意向"),
    #     (3, "成交"),
    #     (4, "未续费"),
    #     (5, "流失"),
    # )

    status_choices = (
        (1, "意向"),
        (2, "跟进"),
        (3, "服务"),
        (4, "未续费"),
        (5, "流失"),
        (5, "对话"),
    )
    status = models.SmallIntegerField(choices=status_choices, verbose_name="状态", default=1)

    remark = models.TextField(verbose_name="备注", null=True, blank=True)

    def __str__(self):
        return self.client_name

    class Meta:
        verbose_name_plural = "客户信息表"


# 跟进记录表
class FollowRecords(models.Model):
    client = models.ForeignKey('ClientInfo', verbose_name="跟进客户")
    create_date = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    update_date = models.DateTimeField(verbose_name="修改时间", auto_now=True)
    content = models.TextField(verbose_name="跟进内容", null=True, blank=True)
    image_url = models.CharField(verbose_name="跟进记录图片", max_length=128, null=True, blank=True)

    def __str__(self):
        return "%s  %s" % (self.client, self.update_date)

    class Meta:
        verbose_name_plural = "客户跟进表"


# 做对话
class DuiHua(models.Model):
    user = models.ForeignKey('UserProfile', verbose_name="所属用户")
    keyworld = models.CharField(verbose_name="关键词", max_length=64)
    link = models.CharField(verbose_name="链接", max_length=512)
    create_date = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    remark = models.TextField(verbose_name="备注", null=True, blank=True)




